package com.hqyj.common.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hqyj.common.pojo.Result;
import com.hqyj.common.pojo.TestPaper;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 考生成绩表 Mapper 接口
 * </p>
 *
 * @author j0701-9
 * @since 2021-10-20
 */
public interface ResultMapper extends BaseMapper<Result> {

    @Select("select avg(score) from result where test_paper_name = #{testPaperName}")
    float queryAvgTestPaperName(String testPaperName);

    @Select("select (select COUNT(*) from result where score >= 60 and test_paper_name = #{testPaperName})\n" +
            "                    /(select COUNT(*) from result where test_paper_name = #{testPaperName})")
    float queryAndPassRateByTestPaperName(String testPaperName);

    @Select("select * from result")
    @Results(id = "oneExamIdToManyTestPaper", value = {
            @org.apache.ibatis.annotations.Result(column = "result_id", property = "resultId"),
            @org.apache.ibatis.annotations.Result(column = "examinee_id", property = "examineeId"),
            @org.apache.ibatis.annotations.Result(column = "name", property = "name"),
            @org.apache.ibatis.annotations.Result(column = "clazz", property = "clazz"),
            @org.apache.ibatis.annotations.Result(column = "test_paper_name", property = "testPaperName"),
            @org.apache.ibatis.annotations.Result(column = "score", property = "score"),
            @org.apache.ibatis.annotations.Result(column = "test_paper_name", property = "testPaper",
                    one = @One(select = "com.hqyj.common.dao.TestPaperMapper.selectTestPaperByTestPaperName"))
    })
    Page<Result> queryTestPaperByExamineeId(Page<Result> resultPage, QueryWrapper<Result> queryWrapper);

    @Select("select * from result")
    @Results(id = "ManyClazzToManyTestPaper", value = {
            @org.apache.ibatis.annotations.Result(column = "result_id", property = "resultId"),
            @org.apache.ibatis.annotations.Result(column = "examinee_id", property = "examineeId"),
            @org.apache.ibatis.annotations.Result(column = "name", property = "name"),
            @org.apache.ibatis.annotations.Result(column = "clazz", property = "clazz"),
            @org.apache.ibatis.annotations.Result(column = "test_paper_name", property = "testPaperName"),
            @org.apache.ibatis.annotations.Result(column = "score", property = "score"),
            @org.apache.ibatis.annotations.Result(column = "clazz", property = "testPaper",
                    one = @One(select = "com.hqyj.common.dao.TestPaperMapper.selectTestPaperByClazz"))
    })
    Page<Result> queryTestPaperByClazz(Page<Result> resultPage, QueryWrapper<Result> queryWrapper);
}
